package com.chixing.controller;


import com.chixing.service.ICouponService;
import com.chixing.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author smith
 * @since 2025-05-21
 */
@RestController
@RequestMapping("/coupon")
public class CouponController {
    @Autowired
    private ICouponService couponService;


    //查询所有优惠卷
    @GetMapping
    public Result getAll(){
        Result result =couponService.getAll();
        return result;
    }



    /**
     * 根据 couponId 获取优惠券
     *
     * @param couponId 优惠券 ID
     * @return Result 返回优惠券的详细信息
     */
    @GetMapping("/{couponId}")
    public Result getCouponById(@PathVariable Integer couponId) {
        return couponService.getCouponById(couponId);
    }


    /**
     * 获取所有优惠券类型
     */
    @GetMapping("/type")
    public Result getCouponTypes() {
        return couponService.getCouponTypes();
    }



    //根据类型名查询
    @GetMapping("/type/{type}")
    public Result getCouponsByType(@PathVariable String type) {
        return couponService.getCouponsByType(type); // 直接返回 Result
    }




}
